package org.example;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class StudentNum {
    public static void main(String[] args) {
        String sql = "select fromcity AS '地区' ,COUNT(fromcity) AS '总人数'from s_student group by fromcity";
        Connection connection = JDBCConn.getConnection();
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try {
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery(sql);
            System.out.println("地区" + "\t" + "总人数");
            while (resultSet.next()) {
                System.out.println(resultSet.getString("地区") + "\t\t" + resultSet.getInt("总人数"));
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}